package cn.simon.controller;


import cn.simon.model.GoodsClassifySec;
import cn.simon.service.GoodsClassifySecService;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;


@Log
@Controller
@RequestMapping("goodsClassifySec")
public class GoodsClassifySecController {
    @Autowired
    private GoodsClassifySecService goodsClassifySecService;

    /**
     * 添加二级分类
     */
    @GetMapping("/add")
    public String addClassifySec(){
        return "addClassifySec";
    }
    @PostMapping("/add")
    public String addClassifySec(GoodsClassifySec goodsClassifySec){
        log.info("-------------------------------------"+goodsClassifySec.toString());
        goodsClassifySecService.addClassifySec(goodsClassifySec);
        return "addClassifySec";
    }
    /**
     * 修改二级分类
     */
    @GetMapping("/update")
    public String updateClassifySec(Model model, Integer id){
        GoodsClassifySec classifySec = goodsClassifySecService.findById(id);
        model.addAttribute("classifySec",classifySec);
        log.info("------------------------------------"+classifySec.toString());
        return "updateClassifySec";
    }
    @PostMapping("/update")
    public String updateClassifySec(GoodsClassifySec goodsClassifySec,Model model){
        model.addAttribute("classifySec",goodsClassifySec);
        log.info("------------------------------------"+goodsClassifySec.toString());
        goodsClassifySecService.updateClassifySec(goodsClassifySec);
        return "redirect:/goodsClassify/findSec?id=" + goodsClassifySec.getClassifyId() ;

    }
    @GetMapping("/delete")
    public String deleteClassifySec(Integer id,GoodsClassifySec goodsClassifySec){
        goodsClassifySecService.deleteClassifySec(id);
        return "redirect:/goodsClassify/findSec?id=" + goodsClassifySec.getClassifyId();
    }
}
